package com.kcl.dfss.utils;

import java.sql.Date;

import com.kcl.dfss.utils.UsageRecordContract.RecordEntry;

import android.content.ContentValues;
import android.text.format.Time;

public class UsageRecord extends DatabaseItem{
	public static final String TABLE_NAME = "table1";
	public static final String COLUMN_NAME_ENTRY_CATEGORY = "category";
	public static final String COLUMN_NAME_ENTRY_DATE = "date";
	public static final String COLUMN_NAME_ENTRY_COST = "cost";
	
	public class CostCategory{
		public String mCategoryType;
		public CostCategory(String type){
			mCategoryType = type;
		}
	}
	private int mID;
	public Date mDate;
	public Time mStartTime;
	public Time mEndTime;
	public float mDistance;
	public float mAveSpeed;
	
	public UsageRecord(String date, String starttime, String endtime, float distance, float avespeed){
		mDate = Date.valueOf(date);
		mEndTime.parse(endtime);
		mStartTime.parse(starttime);
		mDistance = distance;
		mAveSpeed = avespeed;
	}
	
	@Override
	public ContentValues getContentValues() {
		// TODO Auto-generated method stub
		ContentValues values = new ContentValues();
//		values.put(RecordEntry.COLUMN_NAME_ENTRY_ID, mID);
		values.put(RecordEntry.COLUMN_NAME_ENTRY_DATE, mDate.toString());
		values.put(RecordEntry.COLUMN_NAME_ENTRY_START_TIME, mStartTime.toString());
		values.put(RecordEntry.COLUMN_NAME_ENTRY_END_TIME, mEndTime.toString());
		values.put(RecordEntry.COLUMN_NAME_ENTRY_DISTANCE, mDistance);
		values.put(RecordEntry.COLUMN_NAME_ENTRY_AVESPEED, mAveSpeed);
		return values;
	}

	@Override
	public String getCreateDatabaseSQL() {
		// TODO Auto-generated method stub
		return "CREATE TABLE "
				+ TABLE_NAME + " ("
				+ _ID + " INTEGER PRIMARY KEY,"
				+  COLUMN_NAME_ENTRY_DATE + TEXT_TYPE + COMMA_SEP
				+  COLUMN_NAME_ENTRY_CATEGORY + TEXT_TYPE + COMMA_SEP
				+  COLUMN_NAME_ENTRY_COST + FLOAT_TYPE + " )";
	}

	@Override
	public String getDeleteDatabaseSQL() {
		// TODO Auto-generated method stub
		return "DROP TABLE IF EXISTS "+ TABLE_NAME;
	}
	
	public String toString(){
		StringBuilder sb = new StringBuilder();
		sb.append(mDate.toString()+ "  "+mStartTime.toString()+" "+mEndTime.toString()+" "+mDistance+" "+mAveSpeed);
		return sb.toString();
	}

}
